import { _decorator, Component, Node } from 'cc';
import { PopView } from '../manager/AppControll';
import { PopManager } from '../manager/PopManager';
import { GameData } from '../system/GameData';
import { DataHelper } from '../system/DataHelper';
import { SoundManager } from '../manager/SoundManger';
const { ccclass, property } = _decorator;

@ccclass('SkinBtn')
export class SkinBtn extends Component {
    private interval = 20;
    private cur = 0;
    private mNdPoint = null;
    protected onLoad(): void {
        this.mNdPoint = this.node.getChildByName("yellowPoint");
        this.node.on(Node.EventType.TOUCH_END, this.OnSkinBtn, this);
    }

    start() {

    }

    update(deltaTime: number) {
        this.cur++;
        if (this.cur % this.interval == 0) {
            let arr = GameData.playerData.skinFragments;
            let temp = [];
            let isNew = false;
            arr.forEach((elemt) => {
                if (GameData.playerData.skin.indexOf(elemt.skinId) == -1) {
                    temp.push(elemt);
                }
            })
            for (let i = 0; i < temp.length; i++) {
                let config = DataHelper.GetSkin_configById(temp[i].skinId);
                if (temp[i].count >= config.unlockNeedDebris) {
                    isNew = true;
                    break;
                }
            }
            this.mNdPoint.active = isNew;
        }
    }

    OnSkinBtn() {
        SoundManager.Instance<SoundManager>().PlayEffect(GameData.btnClick)
        PopManager.Instance<PopManager>().ShowPop(PopView.skin)
    }
}


